package GUILayer;

import ControlLayer.Ctr;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Customer {
	private Ctr ctr;
	private ModelLayer.Customer c;
	private JFrame frame;
	private JTextField txtFirstName;
	private JTextField txtLastName;
	private JTextField txtAddress;
	private JTextField txtPhoneNumber;
	private JTextField txtCustomerId;
	private JTextField txtId;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;
	private JTextField textField_7;
	private JTextField textField_8;
	private JTextField txtCity;
	private JTextField txtZip;
	private JTextField txtSsn;
	private JTextField textField_9;
	private JTextField textField_10;
	private JTextField textField_11;
	private JTextField textField_12;
	private JTextField textField_13;
	private JTextField textField_14;

	/**
	 * Launch the application.
	 */
	public static void main() {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					
					Customer window = new Customer();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Customer() {
		initialize();
		ctr = new ControlLayer.Ctr();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 822, 526);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		txtFirstName = new JTextField();
		txtFirstName.setText("First name");
		txtFirstName.setBounds(32, 21, 116, 20);
		frame.getContentPane().add(txtFirstName);
		txtFirstName.setColumns(10);
		
		txtLastName = new JTextField();
		txtLastName.setText("Last name");
		txtLastName.setColumns(10);
		txtLastName.setBounds(158, 21, 116, 20);
		frame.getContentPane().add(txtLastName);
		
		txtAddress = new JTextField();
		txtAddress.setText("Address");
		txtAddress.setColumns(10);
		txtAddress.setBounds(32, 52, 116, 20);
		frame.getContentPane().add(txtAddress);
		
		txtPhoneNumber = new JTextField();
		txtPhoneNumber.setText("Phone number");
		txtPhoneNumber.setColumns(10);
		txtPhoneNumber.setBounds(158, 52, 116, 20);
		frame.getContentPane().add(txtPhoneNumber);
		
		JButton btnNewButton = new JButton("Create customer");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				String txtfname = txtFirstName.getText();
				String txtlname = txtLastName.getText();
				String txtaddress = txtAddress.getText();
				String txtphone = txtPhoneNumber.getText();
				String txtcity = txtCity.getText();
				String txtzip = txtZip.getText();
				int Zip = Integer.parseInt(txtzip);
				String txtssn = txtSsn.getText();
				int Ssn = Integer.parseInt(txtssn);
				ctr.insertNewCustomer(txtfname, txtlname, txtaddress, txtcity, Zip, txtphone, Ssn);
			}
		});
		btnNewButton.setBounds(32, 155, 240, 41);
		frame.getContentPane().add(btnNewButton);
		
		txtCustomerId = new JTextField();
		txtCustomerId.setText("Customer ID");
		txtCustomerId.setColumns(10);
		txtCustomerId.setBounds(322, 21, 116, 20);
		frame.getContentPane().add(txtCustomerId);
		
		JButton btnDeleteCustomer = new JButton("Delete customer");
		btnDeleteCustomer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				String id = txtId.getText();
				int ID = Integer.parseInt(id);
				ctr.deleteCustomer(ID);
								
			}
		});
		btnDeleteCustomer.setBounds(305, 80, 150, 41);
		frame.getContentPane().add(btnDeleteCustomer);
		
		JButton btnFindCustomer = new JButton("Find customer");
		btnFindCustomer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String id = txtId.getText();
				int ID = Integer.parseInt(id);
				c = new ModelLayer.Customer();
				c = ctr.findBycID(ID);
				String txtfname = c.getFname();
				String txtlname = c.getLname();
				String txtaddress = c.getAddress();
				String txtphone = c.getPhone();
				String txtcity = c.getCity();
				int txtzip = c.getZip();
				String Zip = Integer.toString(txtzip);
				int txtssn = c.getSsn();
				String Ssn = Integer.toString(txtssn);
				txtFirstName.setText(txtfname);
				txtLastName.setText(txtlname);
				txtAddress.setText(txtaddress);
				txtPhoneNumber.setText(txtphone);
				txtCity.setText(txtcity);
				txtZip.setText(Zip);
				txtSsn.setText(Ssn);
			}
		});
		btnFindCustomer.setBounds(570, 21, 194, 38);
		frame.getContentPane().add(btnFindCustomer);
		
		txtId = new JTextField();
		txtId.setText("ID");
		txtId.setColumns(10);
		txtId.setBounds(497, 21, 52, 38);
		frame.getContentPane().add(txtId);
		
		textField = new JTextField();
		textField.setText("First name");
		textField.setColumns(10);
		textField.setBounds(497, 70, 116, 20);
		frame.getContentPane().add(textField);
		
		textField_1 = new JTextField();
		textField_1.setText("Last name");
		textField_1.setColumns(10);
		textField_1.setBounds(648, 70, 116, 20);
		frame.getContentPane().add(textField_1);
		
		textField_2 = new JTextField();
		textField_2.setText("Address");
		textField_2.setColumns(10);
		textField_2.setBounds(497, 101, 116, 20);
		frame.getContentPane().add(textField_2);
		
		textField_3 = new JTextField();
		textField_3.setText("Phone number");
		textField_3.setColumns(10);
		textField_3.setBounds(648, 101, 116, 20);
		frame.getContentPane().add(textField_3);
		
		JButton btnUpdateCustomer = new JButton("Update customer");
		btnUpdateCustomer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				String txtfname = txtFirstName.getText();
				String txtlname = txtLastName.getText();
				String txtaddress = txtAddress.getText();
				String txtphone = txtPhoneNumber.getText();
				String txtcity = txtCity.getText();
				String txtzip = txtZip.getText();
				int Zip = Integer.parseInt(txtzip);
				String txtssn = txtSsn.getText();
				int Ssn = Integer.parseInt(txtssn);
				String id = txtId.getText();
				int ID = Integer.parseInt(id);
				ctr.updateCustomer(ID, txtfname, txtlname, txtaddress, txtcity, Zip, txtphone, Ssn);
			}
		});
		btnUpdateCustomer.setBounds(614, 220, 150, 51);
		frame.getContentPane().add(btnUpdateCustomer);
		
		textField_4 = new JTextField();
		textField_4.setText("First name");
		textField_4.setColumns(10);
		textField_4.setBounds(32, 220, 116, 20);
		frame.getContentPane().add(textField_4);
		
		textField_5 = new JTextField();
		textField_5.setText("Address");
		textField_5.setColumns(10);
		textField_5.setBounds(32, 251, 116, 20);
		frame.getContentPane().add(textField_5);
		
		textField_6 = new JTextField();
		textField_6.setText("Last name");
		textField_6.setColumns(10);
		textField_6.setBounds(158, 220, 116, 20);
		frame.getContentPane().add(textField_6);
		
		textField_7 = new JTextField();
		textField_7.setText("Phone number");
		textField_7.setColumns(10);
		textField_7.setBounds(158, 251, 116, 20);
		frame.getContentPane().add(textField_7);
		
		textField_8 = new JTextField();
		textField_8.setColumns(10);
		textField_8.setBounds(32, 347, 594, 116);
		frame.getContentPane().add(textField_8);
		
		JButton btnListAllCustomer = new JButton("List all customers");
		btnListAllCustomer.setBounds(32, 298, 194, 38);
		frame.getContentPane().add(btnListAllCustomer);
		
		JButton btnNewButton_1 = new JButton("Back");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.dispose();
			}
		});
		btnNewButton_1.setBounds(636, 422, 128, 41);
		frame.getContentPane().add(btnNewButton_1);
		
		txtCity = new JTextField();
		txtCity.setText("City");
		txtCity.setColumns(10);
		txtCity.setBounds(32, 83, 116, 20);
		frame.getContentPane().add(txtCity);
		
		txtZip = new JTextField();
		txtZip.setText("Zip");
		txtZip.setColumns(10);
		txtZip.setBounds(158, 83, 116, 20);
		frame.getContentPane().add(txtZip);
		
		txtSsn = new JTextField();
		txtSsn.setText("Ssn");
		txtSsn.setColumns(10);
		txtSsn.setBounds(32, 114, 116, 20);
		frame.getContentPane().add(txtSsn);
		
		textField_9 = new JTextField();
		textField_9.setText("City");
		textField_9.setColumns(10);
		textField_9.setBounds(284, 220, 116, 20);
		frame.getContentPane().add(textField_9);
		
		textField_10 = new JTextField();
		textField_10.setText("Zip");
		textField_10.setColumns(10);
		textField_10.setBounds(284, 251, 116, 20);
		frame.getContentPane().add(textField_10);
		
		textField_11 = new JTextField();
		textField_11.setText("Ssn");
		textField_11.setColumns(10);
		textField_11.setBounds(413, 220, 116, 20);
		frame.getContentPane().add(textField_11);
		
		textField_12 = new JTextField();
		textField_12.setText("Ssn");
		textField_12.setColumns(10);
		textField_12.setBounds(497, 165, 116, 20);
		frame.getContentPane().add(textField_12);
		
		textField_13 = new JTextField();
		textField_13.setText("City");
		textField_13.setColumns(10);
		textField_13.setBounds(497, 132, 116, 20);
		frame.getContentPane().add(textField_13);
		
		textField_14 = new JTextField();
		textField_14.setText("Zip");
		textField_14.setColumns(10);
		textField_14.setBounds(648, 132, 116, 20);
		frame.getContentPane().add(textField_14);
	}
}
